#include<iostream>
#include<cstdlib>
#include<unistd.h>
#include<string>
using namespace std;

bool GetSequestParameter(string &parameter)
{
  std::string method=getenv("METHOD");
  bool result;
  int content_length;
  if(method=="GET"){
    parameter=getenv("PARAMETER");
    result=true;
  }
  else if(method=="POST"){
    content_length=atoi(getenv("CONTENT_LENGTH"));
    char ch=0;
    while(content_length){
      read(0,&ch,1);
      parameter.push_back(ch);
      content_length--;
    }
    result=true;
  }
  else{
    result=false;
  }
  return result;
}


void AnalysisParameter(string &analusis,const string &per,string& out1,string& out2){
  auto pos=analusis.find(per);
  if(pos!=std::string::npos){
    out1=analusis.substr(0,pos);
    out2=analusis.substr(pos+per.size());
  }
}

int main()
{
  cerr<<"你好，陈新宇！！！"<<endl;
  string parameter;
  GetSequestParameter(parameter);
  
  string str1;
  string str2;
  AnalysisParameter(parameter,"&",str1,str2);

  string name1;
  string value1;
  AnalysisParameter(str1,"=",name1,value1);

  string name2;
  string value2;
  AnalysisParameter(str2,"=",name2,value2);

  cout<<name1<<":"<<value1<<endl;
  cout<<name2<<":"<<value2<<endl;

  cerr<<name1<<":"<<value1<<endl;
  cerr<<name2<<":"<<value2<<endl;

  return 0;
}
